package csw;

//ctrl + shift + O = 자동 import
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;



public class J24ProfessorDAOImpl implements J24ProfessorDAO {
	
	private static String DRV = "oracle.jdbc.driver.OracleDriver";
	private static String URL = "jdbc:oracle:thin:cswng0831/cswng0831@112.216.253.124:1521:xe";
	
	private static String insertSQL = "";
	private static String selectSQL = " select * from professor order by pfno ";
	private static String selectOneSQL = "";
	private static String updateSQL = "";
	private static String deleteSQL = "";
	
	
	@Override
	public String insertProfessor(J24ProfessorVO pvo) {
		return null;
	}
	@Override
	public ArrayList<J24ProfessorVO> selectProfessor() {
		
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		ArrayList<J24ProfessorVO> pvoes = null;
		
		try{
			conn = makeConn();
			pstmt = conn.prepareStatement(selectSQL);
			rs = pstmt.executeQuery();
			
			pvoes = new ArrayList<>();
			while(rs.next()){
				J24ProfessorVO vo = new J24ProfessorVO();
				vo.setPfno(rs.getString(1));
				vo.setPfname(rs.getString(2));
				vo.setFields(rs.getString(3));
				vo.setSkills(rs.getString(4));
				vo.setRegdate(rs.getString(5));
				pvoes.add(vo);
			}
		}catch(Exception ex){
			ex.printStackTrace();
		}finally{
			closeConn(conn,pstmt,rs);
		}
		
		return pvoes;
	}
	private Connection makeConn() 
				throws Exception{
			Connection conn = null;
			Class.forName(DRV);
			conn = DriverManager.getConnection(URL);
			return conn;
		}
	
	private void closeConn(Connection c, PreparedStatement p,
			ResultSet r) {
		if(r!=null) try{r.close(); }catch(Exception e) {}
		if(p!=null) try{p.close();}catch(Exception e) {}
		if(c!=null) try{c.close(); }catch(Exception e) {}
		
	}
	@Override
	public String updateProfessor(String pfno) {
		return null;
	}
	@Override
	public String deleteProfessor(String pfno) {
		return null;
	}
	@Override
	public ArrayList<J24ProfessorVO> insertOneProfessor(String pfno) {
		return null;
	}

}
